package com.chuan.it_market.service.impl;

import com.chuan.it_market.dao.GoodsDao;
import com.chuan.it_market.dao.SellerDao;
import com.chuan.it_market.dao.ShopCarDao;
import com.chuan.it_market.pojo.entity.Goods;
import com.chuan.it_market.pojo.entity.Seller;
import com.chuan.it_market.pojo.entity.ShopCar;
import com.chuan.it_market.pojo.vo.GoodsVO;
import com.chuan.it_market.pojo.vo.ShopCarVO;
import com.chuan.it_market.service.ShopCarService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShopCarServiceImpl implements ShopCarService {

    @Resource
    ShopCarDao shopCarDao;
    @Resource
    SellerDao sellerDao;
    @Resource
    GoodsDao goodsDao;

    @Override
    public int insert(ShopCar shopCar) {
        return shopCarDao.insertSelective(shopCar);
    }

    @Override
    public List<ShopCarVO> selectCarsByprimaryKey(Integer bno) {
        List<ShopCarVO> shopCarVO= shopCarDao.selectByBno(bno);

            for(ShopCarVO s:shopCarVO)
            {
                Seller seller= sellerDao.selectByPrimaryKey(s.getSno());
                Goods goods=goodsDao.selectByPrimaryKey(s.getGno());
                s.setSeller(seller);
                s.setGoods(goods);
            }
        return shopCarVO;
    }

    @Override
    public Integer selectCarsCountByBno(Integer bno) {
        return shopCarDao.selectCarsCountByBno(bno);
    }

    @Override
    public int delete(Integer cno) {
        return shopCarDao.deleteByPrimaryKey(cno);
    }
}
